<template>
	<view class="dialog">
		<el-dialog :title="title" :visible.sync="dialogVisible" width="40%" :before-close="handleDialogClose">
			<!-- 广告位审核 -->
			<el-form ref="form" :model="form" label-width="130px" :rules="rules">
				<el-form-item label="广告链接" class="item" prop="link">
					<el-input v-model="form.link" placeholder="请输入广告链接"></el-input>
				</el-form-item>
				<el-form-item label="每PV价格" class="item" prop="select2">
					<el-input v-model="form.pvPrice"></el-input>
				</el-form-item>
				<el-form-item label="每UV价格" class="item" prop="select1">
					<el-input v-model="form.uvPrice"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="handleClose(2)" v-preventReClick>通过</el-button>
				<el-button type="danger" @click="handleClose(3)" v-preventReClick>拒绝</el-button>
				<el-button @click="handleClose(false)">取 消</el-button>
			</span>
		</el-dialog>
	</view>
</template>
<script>
	import {
		Request
	} from '../../model/request.js'
	import {
		Util
	} from '../../utils/util.js'
	// import {
	// 	config
	// } from "../../api/config.js";
	// import {
	// 	ServerUrl
	// } from "../../api/server_url.js";
	export default {
		props: {
			dialogVisible: '',
			second: '',
			title: '广告位审核',
			item: {}
		},
		
		data() {
			return {
				form: {
					link: '',
					pvPrice: '',
					uvPrice: ''
				},
				selectArr1: [], // 标签
				selectArr2: [], // 广告
				currentSelectArr: [],
				rules: {
					linkName: [{
						required: true,
						message: '请输入媒体名称',
						trigger: 'blur'
					}],
					select1: [{
						required: true,
						message: '请选择',
						trigger: 'change'
					}],
					select2: [{
						required: true,
						message: '请选择',
						trigger: 'change'
					}],
					link: [{
							required: true,
							message: '请填写网站域名',
							trigger: 'blur'
						},
						{
							pattern: /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/,
							message: '请输入正确的域名地址'
						}
					],
					keyword: [{
						required: true,
						message: '请填写广告关键词',
						trigger: 'blur'
					}],
					profile: [
						{
							required: true,
							message: '请填写媒体简介，不得少于40字',
							trigger: 'blur'
						},
						{
							pattern: /[\w\W]{40}/,
							message: '不得少于40字'
						}
					]
				}
			}
		},
		
		mounted() {
			
		},
		
		watch: {
			dialogVisible(newVal) {
				
			}
		},
		
		methods: {
			handleDialogClose(flag=false) {
				this.form = {
					username: '',
					pwd: '',
					phone: '',
					email: '',
					contacts: '',
					bankNumber: '',
					toBank: '',
					address: '',
					linkName: '',
					link: '',
					channel: '',
					linkState: 1,
					newLink: ''
				}
				this.$refs.form.clearValidate()
				this.$emit('closeDialog', flag)
			},
			
			async handleClose(e) {
				if (e) {
					if (e == 1) { // 提交审核审核
						this.$refs.form.validate(async (valid) => {
							if (valid) { // 效验成功，无错误
							console.log(123123, '晓燕成功')
								// let res = await Request.MEDIAADD({
								// 	mcAdvertising: this.form.select1, // 行业广告
								// 	mcMal: this.form.select2, 		// 行业标签
								// 	mcToa: this.form.radio, 		// 是否支持下载类广告
								// 	mediaIntro: this.form.profile, 	// 媒体简介
								// 	mediaKeyword: this.form.keyword,// 媒体关键字
								// 	mediaName: this.form.linkName, 	// 媒体名称
								// 	websiteName: this.form.link		// 网站域名
								// })
								// if (res.code == 200) {
								// 	Util.showToast('添加成功')
								// 	this.handleDialogClose(true)
								// }
							} else {
								console.log('效验不成功，提交失败')
								return false
							}
						})
					} else if (e == 2) { // 通过
						console.log('执行了,,,,,,,,,,,,,', this.item.mediaId)
						let res = await Request.MEDIAUPDATE(
							this.item.mediaId,
							0
							// mcToa: this.form.radio, 		// 是否支持下载类广告
							// mediaIntro: this.form.profile, 	// 媒体简介
						)
						if (res.code == 200) {
							Util.showToast('审核成功')
							this.handleDialogClose(true)
						}
					} else if (e == 3) { // 拒绝
						let res = await Request.MEDIAUPDATE(
							this.item.mediaId,
							3
							// mcToa: this.form.radio, 		// 是否支持下载类广告
							// mediaIntro: this.form.profile, 	// 媒体简介
						)
						if (res.code == 200) {
							Util.showToast('审核成功')
							this.handleDialogClose(true)
						}
					}
				} else {
					this.handleDialogClose()
				}
			}
		}
	}
</script>
<style scoped>
	.dialog {
		/* width: 100%;
	height: 100%; */
		position: absolute;
		left: 0;
		top: 0;
	}

	.el-form-item {
		position: relative;
	}

	.el-form-item::before {
		content: '*';
		position: absolute;
		left: 100px;
		top: 13px;
		color: red;
	}

	/deep/ .item .el-form-item__label {
		position: relative;
		left: -20px;
		/* color: red;
		border: solid 1px red;
		margin-left: 30px; */
	}

	/deep/ .item .el-form-item__label::before {
		content: ' ' !important;
	}

	.photo {
		width: 299px;
		height: 200px;
	}
	
	.el-select {
		width: 100%;
	}
</style>
